Repository navigation
fix: make email ingress fail loudly and stop blocking on slow dependencies - #3
Merged
Merged
Conversation
…ncies
Worker: a non-2xx or thrown fetch to the API was logged and the email
dropped while the sender saw success. The worker now times the fetch out
at 25s and calls setReject on any failure. The Workers types document
setReject as a permanent SMTP error only, so 5xx/429/timeouts bounce
with "Temporary failure, please retry" rather than being retried by the
sender's MTA.
API:
- Ingress body limit is 16 MB for POST /v1/inboxes/{address}/emails with
a valid worker secret (attachments are base64-encoded into one JSON
body, so 10 MB of raw mail always 413'd); other routes stay at 10 MB.
Chunked ingress bodies get 411. Test asserts the handler does not run
after a 413.
- SseManager drops the oldest event instead of suspending, so a stalled
SSE client can no longer block ingest. SSE streams send a keepalive
comment every 25s and close when the session has expired.
- TursoClient retries network errors, timeouts, 5xx and 429 (3 attempts,
200ms/600ms backoff), never 4xx; request timeout 30s -> 10s; empty
responses raise a clear error instead of NoSuchElementException.
- /health is SELECT 1 only and returns {status}; the unauthenticated
COUNT(*) stats are removed (nothing in web/ or cli/ reads them).
/livez returns 200 without touching the DB.
- Attachments are decoded and validated before the email row is
inserted, so bad base64 no longer leaves an orphan row.
- Decrypt failures log at ERROR and return a placeholder body (or fail
the attachment download) instead of returning ciphertext.
bmc08gt
force-pushed
the
fix/ingress-resilience
branch
from
October 1, 2026 02:20
aa82fd5 to
a333942
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Ingest dropped mail silently on any API error, rejected anything over about 7 MB, and could be stalled by a slow SSE client or a transient Turso error.
Worker (
workers/email-ingress)message.setReject(...); before, it was logged and the sender saw success.setRejectis documented in@cloudflare/workers-typesas a permanent SMTP error only, so 5xx, 429 and timeouts bounce with "Temporary failure, please retry" instead of being retried by the sender's MTA. There is no temporary-failure API.att.contentcan be a string in the installed postal-mime types, which failedtsc; it is now encoded to bytes.API
POST /v1/inboxes/{address}/emailswith a matchingX-Worker-Secret, 10 MB elsewhere. Chunked ingress bodies get 411.BodyLimitTestchecks the handler does not run after a 413.SseManager.publishusesDROP_OLDESTandtryEmit, so it no longer suspends insideingestEmail. SSE streams write a: keepalivecomment every 25s and close when the session has expired.TursoClient: 3 attempts (200ms, 600ms) on network errors, timeouts, 5xx and 429; never 4xx. Request timeout 30s to 10s. An empty response raises a clear error./healthrunsSELECT 1and returns{status}. The COUNT(*) stats are removed; nothing inweb/orcli/reads them./livezreturns 200 without the DB.[This message could not be decrypted]; attachment downloads fail instead of returning ciphertext. Emails stored before an inbox had an encryption key will also hit this path, since the old code fell back to the raw value.Deploy
blip.sha.wrangler deployinworkers/email-ingress; there is no automated deploy yet.